Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform provider ProfitBricks - Data Sources #11520

Merged
merged 25 commits into from
Feb 2, 2017
Merged

Terraform provider ProfitBricks - Data Sources #11520

merged 25 commits into from
Feb 2, 2017

Conversation

jasmingacic
Copy link

While this PR is fresh I have two issues with unit tests:

  1. resource_profitbricks_loadbalancer_test - The issue is within ProfitBricks API. When a load balancer is provisioned it creates a private LAN and attaches it to existing NIC. This is leaving .tfstate with "dangling resources". This is a known issue with ProfitBricks

  2. resource_profitbricks_volume_test - The script used for unit tests is working when ran separately but once unit tests run I get this error:

        testing.go:265: Step 1 error: Check failed: Check 1/2 error: Bad name: webserver

I'm not sure how to fix this.
@stack72 do you have any ideas?

jasminSPC added 3 commits January 31, 2017 17:01
- nat parameter for Nics
- availabilityZone for Volumes

Minor code clean up
@jasmingacic
Copy link
Author

I'm using this PR to update to ProfitBicks REST V3. Adding following parameters:

  • nat parameter for Nics
  • availabilityZone for Volumes

@stack72
Copy link
Contributor

stack72 commented Feb 1, 2017

👀 are on this now @jasminSPC

Copy link
Contributor

@stack72 stack72 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jasminSPC

So the new data sources look good - I am not quite sure what we can do about the dangling resources

If this is an error on the profitbricks side, then we may need to have a step n the CheckDestroy that cleans everything up for us. Alternatively, we can have a script that runs after the tests that cleans up any dangling resources - the maintainer of the scaleway provider did the same thing here

With regards to that unit test - let's not worry too much about that right now - I will dig into that soon and have a look at what is going on there

P.

return fmt.Errorf("An error occured while fetching datacenters %s", datacenters.Response)
}

name, _ := d.GetOk("name")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as it's a required field we can guarantee it's there so we can write

name := d.Get("name").(string)

"testing"
)

func TestAccDataSourceDatacenter_basic(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see a test that matches a datacenter name here :)

Copy link
Author

@jasmingacic jasmingacic Feb 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is tricky in order to get a match we need to have a data center. I'm not sure how to accomplish that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the test, have 2 steps, the first as a setup to create the datacenter, then the second will include a datacenter and a lookup

have a look at this test as an example https://github.com/hashicorp/terraform/blob/master/builtin/providers/aws/data_source_aws_autoscaling_groups_test.go#L15

Copy link
Author

@jasmingacic jasmingacic Feb 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried something similar:

In first step I do this:

resource "profitbricks_datacenter" "foobar" {
	name       =  "datacenter-test"
	location = "us/las"
}

and then this.

resource "profitbricks_datacenter" "foobar" {
	name       =  "datacenter-test-updated"
	location = "us/las"
}

data "profitbricks_datacenter" "data_source"{
	name = "datacenter-test-updated"
	location= "us/las"
}

Each time I do this it simply doesn't work.
How do you want me to proceed?

return fmt.Errorf("An error occured while fetching ProfitBricks locations %s", images.Response)
}

name, _ := d.GetOk("name")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name isn't required, so we should check it's ok before using it

Type: schema.TypeString,
Optional: true,
},
"id": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually don't need to expose Id as a param - it's there by default

Type: schema.TypeString,
Optional: true,
},
"id": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually don't need to expose Id as a param - it's there by default

return fmt.Errorf("There are no images that match the search criteria")
}

d.Set("name", results[0].Properties.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check that Properties != nil ? Otherwise we could panic here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Properties ImageProperties `json:"properties,omitempty"
It can't be nil it is not a pointer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 sorry - still in AWS land where everything is a pointer :)

Type: schema.TypeString,
Optional: true,
},
"id": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually don't need to expose Id as a param - it's there by default

@jasmingacic
Copy link
Author

The loadbalancer thing is a known issue with ProfitBricks and we can't do much about that.
I can add cleanup in check destroy to wipe all orphaned resource.

…ng sure that the test doesn't leave dangling resources in ProfitBricks
@stack72
Copy link
Contributor

stack72 commented Feb 2, 2017

Hey

so i just went through this and it looks good - I ran the tests and got 1 error

% make testacc TEST=./builtin/providers/profitbricks TESTARGS='-run=TestAccDataSource'                                                   1 ↵ ✭
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/02/02 10:39:44 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/profitbricks -v -run=TestAccDataSource -timeout 120m
=== RUN   TestAccDataSourceDatacenter_basic
--- PASS: TestAccDataSourceDatacenter_basic (0.64s)
=== RUN   TestAccDataSourceImage_basic
--- FAIL: TestAccDataSourceImage_basic (0.55s)
	testing.go:265: Step 0 error: Check failed: Check 2/3 error: data.profitbricks_image.img: Attribute 'name' expected "Ubuntu-16.04-LTS-server-2017-01-01", got "Ubuntu-16.04-LTS-server-2017-02-01"
=== RUN   TestAccDataSourceLocation_basic
--- PASS: TestAccDataSourceLocation_basic (0.61s)
FAIL
exit status 1
FAIL	github.com/hashicorp/terraform/builtin/providers/profitbricks	1.824s
make: *** [testacc] Error 1

I think we are going to have an issue with that test if it revs a version each month though so all in all this is looking good

P.

@jasmingacic
Copy link
Author

The problem with the test is that ProfitBricks is changing image names on monthly basis.
I guess I should add custom check for this.
@stack72 What do you think?

@stack72
Copy link
Contributor

stack72 commented Feb 2, 2017

This LGTM! :)

% make testacc TEST=./builtin/providers/profitbricks TESTARGS='-run=TestAccDataSource'                                                       ✭
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/02/02 13:25:28 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/profitbricks -v -run=TestAccDataSource -timeout 120m
=== RUN   TestAccDataSourceDatacenter_matching
--- PASS: TestAccDataSourceDatacenter_matching (12.29s)
=== RUN   TestAccDataSourceImage_basic
--- PASS: TestAccDataSourceImage_basic (0.67s)
=== RUN   TestAccDataSourceLocation_basic
--- PASS: TestAccDataSourceLocation_basic (0.46s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/profitbricks	13.433s

@stack72 stack72 merged commit b862cd2 into hashicorp:master Feb 2, 2017
@ghost
Copy link

ghost commented Apr 17, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants